<template>
  <div>
    <!-- 首页小卡片信息 -->
    <div class="card-content1 shadow-box background-opacity">
      <el-avatar style="margin-top: 20px" class="user-avatar" :size="120"
                 :src="$store.state.webInfo.avatar"></el-avatar>
      <div class="web-name">{{ $store.state.webInfo.webName }}</div>
      <div class="web-info">
        <div class="blog-info-box">
          <span>文章</span>
          <span class="blog-info-num">{{ statistics.articleCount }}</span>
        </div>
        <div class="blog-info-box">
          <span>分类</span>
          <span class="blog-info-num">{{ statistics.sortCount }}</span>
        </div>
        <div class="blog-info-box">
          <span>文章热度</span>
          <span class="blog-info-num">{{ statistics.viewCount }}</span>
        </div>
      </div>
      <a class="collection-btn" @click="showTip()">
        <i class="el-icon-star-off" style="margin-right: 2px"></i>朋友圈
      </a>
    </div>

    <!-- 搜索 -->
    <div style="padding: 15px;border-radius: 10px;margin-top: 30px;animation: hideToShow 1s ease-in-out"
         class="shadow-box background-opacity wow">
      <div style="color: var(--lightGreen);font-size: 20px;font-weight: bold;margin-bottom: 10px">
        搜索
      </div>
      <div style="display: flex">
        <input class="ais-SearchBox-input" type="text"
               v-model="articleTitle"
               @keyup.enter="enter()"
               placeholder="搜索文章" maxlength="32">
        <div class="ais-SearchBox-submit" @click="searchArticle()">
          <svg style="margin-top: 3px;margin-left: 18px" viewBox="0 0 1024 1024" width="20" height="20">
            <use xlink:href="#icon-sousuo"/>
          </svg>
        </div>
      </div>
    </div>

    <!-- 推荐文章 -->
    <div v-if="!$common.isEmpty(recommendArticles)"
         style="padding: 25px;border-radius: 10px;margin-top: 30px;animation: hideToShow 1s ease-in-out"
         class="shadow-box background-opacity wow">
      <div class="card-content2-title">
        <i class="el-icon-reading card-content2-icon"></i>
        <span>推荐文章</span>
      </div>
      <div v-for="(article, index) in recommendArticles"
           :key="index"
           @click="$router.push({path: '/article', query: {id: article.id}})">
        <div class="aside-post-detail">
          <div class="aside-post-image">
            <el-image lazy class="my-el-image" :src="article.articleCover" fit="cover"/>
          </div>
          <div class="aside-post-title">
            {{ article.articleTitle }}
          </div>
        </div>
        <div class="aside-post-date">
          <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-rili"/>
          </svg>
          {{ article.createTime }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  data() {
    return {
      recommendArticles: [],
      articleTitle: "",
      statistics: {
        articleCount: 0,
        sortCount: 0,
        viewCount: 0
      },
    }
  },
  computed: {},
  created() {
    this.getStatistics();
    this.getRecommendArticles();
  },
  methods: {
    getStatistics() {
      this.$createHttp.getStatistics()
        .then((res) => {
          if (res.code === 200) {
            this.statistics = res.data;
          }
        })
        .catch((error) => {
          this.$message({
            message: error,
            type: "error"
          });
        });
    },
    getRecommendArticles() {
      this.$createHttp.getRecommendArticle()
        .then((res) => {
          if (!this.$common.isEmpty(res.data)) {
            this.recommendArticles = res.data;
          }
        })
        .catch((error) => {
          this.$message({
            message: error,
            type: "error"
          });
        });
    },
    enter() {
      this.searchArticle();
    },
    searchArticle() {
      if (this.articleTitle !== "") {
        this.$router.push({path: '/articlePage', query: {articleTitle: this.articleTitle}});
      }
    },
    showTip() {
      this.$router.push({path: '/weiYan'});
    }
  }
}
</script>

<style scoped>
.card-content1 {
  background: linear-gradient(-45deg, #e8d8b9, #eccec5, #a3e9eb, #bdbdf0, #eec1ea);
  background-size: 400% 400%;
  animation: gradientBG 10s ease infinite;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 10px;
  position: relative;
  /*color: var(--white);*/
  overflow: hidden;
}

.card-content1 :not(:first-child) {
  z-index: 10;
}

.web-name {
  font-size: 30px;
  font-weight: bold;
  margin: 20px 0;
}

.web-info {
  width: 80%;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
}

.blog-info-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
}

.blog-info-num {
  margin-top: 12px;
}

.collection-btn {
  position: relative;
  margin-top: 12px;
  background: var(--lightGreen);
  cursor: pointer;
  width: 65%;
  height: 35px;
  border-radius: 1rem;
  text-align: center;
  line-height: 35px;
  color: var(--white);
  overflow: hidden;
  z-index: 1;
  margin-bottom: 25px;
}

.collection-btn::before {
  background: var(--gradualRed);
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  content: "";
  transform: scaleX(0);
  transform-origin: 0;
  transition: transform 0.5s ease-out;
  transition-timing-function: cubic-bezier(0.45, 1.64, 0.47, 0.66);
  border-radius: 1rem;
  z-index: -1;
}

.collection-btn:hover::before {
  transform: scaleX(1);
}

.card-content2-title {
  font-size: 18px;
  margin-bottom: 20px;
}

.card-content2-icon {
  color: var(--red);
  margin-right: 5px;
  animation: scale 1s ease-in-out infinite;
}

.aside-post-detail {
  display: flex;
  cursor: pointer;
}

.aside-post-image {
  width: 40%;
  border-radius: 0.2rem;
  margin-right: 8px;
  overflow: hidden;
}

.aside-post-title {
  width: 60%;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.aside-post-date {
  margin-top: 8px;
  margin-bottom: 20px;
  color: var(--greyFont);
  font-size: 12px;
}

.ais-SearchBox-input {
  padding: 0 14px;
  height: 30px;
  width: calc(100% - 50px);
  outline: 0;
  border: 2px solid var(--lightGreen);
  border-right: 0;
  border-radius: 40px 0 0 40px;
  color: var(--maxGreyFont);
  background: var(--white);
}

.ais-SearchBox-submit {
  height: 30px;
  width: 50px;
  border: 2px solid var(--lightGreen);
  border-left: 0;
  border-radius: 0 40px 40px 0;
  background: var(--white);
  cursor: pointer;
}

</style>
